package cn.openea.perpartner.meily.homepagesearch.mapper;

import cn.openea.perpartner.meily.homepagesearch.entity.Task;
import cn.openea.perpartner.meily.web.entity.Job;
import cn.openea.perpartner.meily.web.entity.TaskHall;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author rains
 * @since 2023-06-29 15:33
 */
public interface TaskMapper extends BaseMapper<Task> {
//    @Select("SELECT '0' as type job_name as title FROM meily_job where status = '招聘中' ${ew_job.customSqlSegment} " +
//            "UNION" +
//            "SELECT task_name as title FROM meily_task_hall where task_status = '上架' and collect_type = 'market' ${ew-taskHall.customSqlSegment} ")

    @Select("(select '0' as type, job_name as title, company as subtitle, IF(job_top > 0, '热', IF(DATE_ADD(create_time, INTERVAL 8 DAY) > now() , '新','')) as titleLabel, IF(job_top > 0, '#ffa800',IF(DATE_ADD(create_time, INTERVAL 8 DAY) > now() , '#ea4d5e','')) as titleColor, salary as price, CONCAT_WS(',', experiece, degree, type, requirements) as labels, '' as labelsColor, '' as couponLabel,  create_time as createTime, IF(avatar = '男', 'https://dev-1308272144.cos.ap-guangzhou.myqcloud.com/Meily/img/boy.png', IF(avatar = '女', 'https://dev-1308272144.cos.ap-guangzhou.myqcloud.com/Meily/img/girl.png', '')) as images, job_id as businessId, CONCAT('/pages_tabbar_contact/index_contact/jobDetails?jobId=', job_id) as jumpUrl, CONCAT('{','\"leader\":\"', leader,'\",','\"posts\":\"', posts,'\",','\"area\":\"', area,'\"}') as extraJSON FROM meily_job where status = '招聘中' ${ew.customSqlSegment} )" +
            " UNION " +
            "(select '1' as type, task_name as title, '' as subtitle, task_keyword as titleLabel, '#40972f' as titleColor, task_price as price, task_label as labels, task_color as labelsColor, coupon_label as couponLabel, create_time as createTime, image_url as images, task_current_id as businessId, task_url as jumpUrl, null as extraJSON FROM meily_task_hall where task_status = '上架' and collect_type = 'market' ${ew.customSqlSegment} ) ")
    List<Task> getJobAndTaskHallList(@Param("ew") LambdaQueryWrapper<Job> jobQueryWrapper, @Param("ew") LambdaQueryWrapper<TaskHall> taskHallQueryWrapper);
}
